<template>
	<div id="main-form">
		<el-form :rules="addRules" :model="manMessage" ref="addManMessRef">
			<h3 style="color: red; margin-left: 40px">请填写易付宝企业账号用于收款及身份核实</h3>
			<hr>
			<h2 style="margin-left: 40px">填写信息</h2>
			<div style="margin-left: 150px">
				<br>
				<el-form-item prop="inMoneyNum">
					<b>易付宝企业账号 </b>
					<el-input placeholder="请输入内容" style="width: 800px" v-model="manMessage.inMoneyNum"></el-input>
				</el-form-item>
				<br>
				<el-form-item prop="statusNum">
					<b>法人身份证号 </b>
					<el-input placeholder="请输入内容" style="width: 800px" v-model="manMessage.statusNum"></el-input>
				</el-form-item>
				<br>
			</div>
			<hr>
			<h2 style="margin-left: 40px">确认信息</h2>
			<div style="margin-left: 150px">
				<br>
				<div>
					<i class="el-icon-user-solid"></i> <span style="font-size: 20px">易购账户名：</span>
					<span style="color: red">{{username}}</span>
					<br><br>
					<div style="margin-left: 60px; font-size: 20px">您正在使用该账号发起众筹项目</div>
				</div>
				<br>
			</div>
			<hr>
			<div id="main-sub">
				<el-button type="primary" @click="backItem">上一步</el-button>
				<el-button type="primary" @click="nextItem">下一步</el-button>
			</div>
		</el-form>
	</div>
</template>

<script>
	import hub from '../js/EventVue'
	export default {
		data() {
			var checkstatusNum = (rule, value, callback) => {
				if (!value) {
					return callback(new Error("筹资金额不能为空"))
				}
				var reg = /^[0-9]{18}$/
				if (!reg.test(value)) {
					return callback(new Error("筹资金额不合法"))
				}
				return callback();
			};
			return {
				username: "",
				iid: 0,
				manMessage: {
					inMoneyNum: "",
					statusNum: ""
				},
				addRules: {
					inMoneyNum: [{
							required: true,
							message: '收款账号不能为空',
							trigger: 'blur'
						},
						{
							min: 11,
							max: 11,
							message: '收款账号长度在 11 个字',
							trigger: 'blur'
						}
					],
					statusNum: [{
						validator: checkstatusNum,
						trigger: 'blur'
					}]
				}
			}
		},
		methods: {
			async nextItem() {
				await this.$refs.addManMessRef.validate(async (val) => {
					if (val) {
						//向item-man表中添加收款账号和法人身份证号
						let param = new URLSearchParams();
						param.append("inmoneynum", this.manMessage.inMoneyNum);
						param.append("statusnum", this.manMessage.statusNum);
						param.append("iid", this.iid);
						let res = await this.$http.post("addOtherMessToItemMan", param);
						//向item表中添加状态
						let par = new URLSearchParams();
						par.append("iid", this.iid);
						let resp = await this.$http.post("addStatusToItemById", par);
						if (res.data.code == 200 && resp.data.code == 200) {
							//跳转
							this.$emit("forNum", 4)
							await this.$router.push("/s_s_4");
							alert("请进行下一步操作")
						}
					} else {
						alert("格式错误 请修正")
					}
				})

			},
			backItem() {
				this.$router.push("/s_s_2");
			},
			//动态获取当前账号
			async selectUsernameById() {
				//从全局获取id
				var id = window.sessionStorage.getItem("userid");
				//根据id查询账号
				var res = await this.$http.get("selectById?id=" + id);
				this.username = res.data.data.username;
			}
			
		},
		mounted() {
			this.iid = this.$route.params.iid;
			this.selectUsernameById();
		}
		// created() {
		//   /*this.selectUsernameById();*/
		//   //从兄弟组件中获取值
		//   let that = this;
		//   hub.$on('iid',(val) => {
		//     that.iid = val
		//   })
		// }, 
		// beforeDestroy() {
		//   //兄弟组件传值 把iid传入下一步
		//   hub.$emit('iid',this.iid)
		// } 
	}
</script>

<style scoped>
	b {
		display: inline;
		width: 150px;
		line-height: 30px;
		float: left;
	}

	#main-sub {
		line-height: 60px;
		margin: 0 auto;
		text-align: center;
	}
</style>
